import { Body, Controller, Get, Inject, Post } from '@nestjs/common';
import { ApiOperation, ApiTags } from '@nestjs/swagger';
import { type } from 'os';
import { PageQuery } from 'src/common/page/PageQuery';
import { PageResult } from 'src/common/page/PageResult';
import { Result } from 'src/common/Result';
import { Type } from 'src/entity/Type';
import { TypeService } from 'src/service/TypeService';

@ApiTags("种类模块")
@Controller("/type")
export class TypeController {

    @Inject()
    private typeService: TypeService;

    /**
     * 种类列表查询
     * @param query 
     * @returns 
     */
    @ApiOperation({summary: "种类列表查询"})
    @Post("/selectTypeList")
    async selectTypeList(@Body() query: PageQuery<Type>) {
        let data = await this.typeService.selectTypeList(query);
        return Result.success("成功", PageResult.of(data))
    }

    /**
     * 添加种类
     * @param type 
     * @returns 
     */
    @ApiOperation({summary: "添加种类"})
    @Post("/add")
    async addType(@Body() type: Type) {
        return this.typeService.addType(type);
    }

    /**
     * 编辑种类
     * @param type 
     */
    @ApiOperation({summary: "编辑种类"})
    @Post("/update")
    async update(@Body() type: Type) {
        return this.typeService.update(type);
    }
}